package com.wynn.dao;

import com.wynn.pojo.Bom;
import com.wynn.pojo.Product;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Mapper
public interface ProductDao {

    @Select("select * from product where id =#{id}")
    Product findProductById(int id);

    @Select("select * from product")
    List<Product> findAllProduct();

    @Insert({"insert into product values(null,#{productModel},#{productName},#{ct},#{temperature},#{cryogen}," +
            "#{size},#{voltage},#{price})"})
    int add(Product product);

    @Select("select * from product where productModel=#{productModel}")
    Product selectByModel(Product product);

    @Delete("delete from product where id = #{id}")
    int delete(int id);

    @Update("update product set productModel=#{productModel},productName=#{productName},ct=#{ct},temperature=#{temperature}," +
            "cryogen=#{cryogen},size=#{size},voltage=#{voltage},price=#{price} where id=#{id}")
    int edit(Product product);

    @Select("select * from product where productModel=#{productModel}")
    List<Product> search(String productModel);

    @Select("select * from bom where fatherId=#{futherId}")
    List<Bom> findAllBomByFid(int futherId);

    @Insert("insert into bom values(null,#{name},#{num},#{fatherId},#{content})")
    void bomAdd(Bom bom);

    @Delete("delete from bom where id=#{id}")
    void deleteBom(int id);

    @Update("update bom set name=#{name},num=#{num},content=#{content} where id =#{id}")
    void editBom(Bom bom);

    @Select("select * from bom where name=#{name}")
    List<Bom> findAllBomByName(String name);
}
